<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="shortcut icon" href="../img/eraser-32.png"/>
    <link rel="bookmark" href="../img/eraser-32.png" type="image/x-icon"/>
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>

</head>
<body class="hold-transition">
<div id="app">
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"></el-input>
                <el-button @click="pagination.currentPage=1;findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新增</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="orderDate" label="体检日期" align="center"></el-table-column>

                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号" align="center"></el-table-column>
                <el-table-column prop="setmealName" label="检查套餐" align="center"></el-table-column>
                <el-table-column label="报告状态" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.reportStatus == '1' ? '报告未上传' : '报告已上传'}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">上传报告</el-button>
                        <el-button size="medium" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新建用户" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddForm" label-position="right" :model="formData" :rules="rules"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="体检日期" prop="orderDate">
                                                <el-date-picker v-model="formData.orderDate"
                                                                type="date"
                                                                :picker-options="pickerOptions" placeholder="选择日期"
                                                >
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="档案号" prop="fileNumber">
                                                <el-input v-model="formData.fileNumber"/>
                                            </el-form-item>
                                        </el-col>

                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="选择检查套餐(单选)" name="second">
                                <div class="checkScrol">
                                    <div class="checkScrol">
                                        <table class="datatable">
                                            <thead>
                                            <tr>
                                                <th>序号</th>
                                                <th>套餐编码</th>
                                                <th>套餐名称</th>
                                                <th>说明</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr v-for="s in tableData">

                                                <td>
                                                    <input :id="s.id" v-model="setmealIds" type="checkbox"
                                                           :value="s.id">
                                                </td>
                                                <td><label :for="s.id">{{s.code}}</label></td>
                                                <td><label :for="s.id">{{s.name}}</label></td>
                                                <td><label :for="s.id">{{s.remark}}</label></td>

                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="上传报告" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="上传报告" name="first">
                                <el-form ref="editData" label-position="right" :model="formData" label-width="100px">
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="上传文件">
                                                <el-upload action="/physical/upload.do"
                                                           class="avatar-uploader"
                                                           name="PDFFile"
                                                           :show-file-list="false"
                                                           :on-success="handleAvatarSuccess"
                                                           :before-upload="beforeAvatarUpload">
                                                    <img v-if="imageUrl" :src="imageUrl" class="avatar">
                                                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                                </el-upload>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="uploadReportCreate()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<!--引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../plugins/healthmobile.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            imageUrl: null,
            activeName: 'first',
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            setmealIds: [],
            tableData: [],
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//添加表单时候可见
            rules: {//校验规则
                orderDate: [{required: true, message: '体检日期为必填项', trigger: 'blur'}],
                phoneNumber: [{required: true, message: '手机号为必选项', trigger: 'blur'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },

        methods: {
            //文件上传成功后的钩子，response为服务端返回的值，file为当前上传的文件封装成的js对象
            handleAvatarSuccess(response, file) {
                this.imageUrl = 'qi8cx8o66.hn-bkt.clouddn.com/' + response.data;
                if (response.flag) {
                    this.$message({
                        message: response.message,
                        type: 'success'
                    });
                } else {
                    this.$message.error(response.message);
                }
                this.formData.report = this.imageUrl;

                this.imageUrl = "http://qi8cx8o66.hn-bkt.clouddn.com/timg.jpg";
            },
            //上传之前执行
            beforeAvatarUpload(file) {
                const isPDF = file.type === 'application/pdf';
                if (isPDF) {
                    return true;
                }
                this.$message.error('上传文件只能是PDF格式!');
                return false;
            },
            //分页查询
            findPage() {
                //发送ajax请求，提交分页相关请求参数（页码、每页显示记录数、查询条件）
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/physical/findPage.do", param).then((resp) => {
                    this.pagination.total = resp.data.total;
                    this.dataList = resp.data.rows;
                })
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
                //默认切换到第一个标签(基本信息)
                this.activeName = 'first';
                //重置
                this.setmealIds = [];
                //发送请求
                axios.post("/setmeal/findAll.do").then((resp) => {
                    if (resp.data.flag) {
                        this.tableData = resp.data.data;
                    } else {
                        this.$message.error(resp.data.message);
                    }
                });
            },

            //添加
            handleAdd() {
                var telephone = this.formData.phoneNumber;
                if (!checkTelephone(telephone)) {
                    this.$message.error('请输入正确的手机号');
                    return false;
                }
                var today = new Date();
                if (today < this.formData.orderDate) {
                    this.$message.error('体检日期必须小于当前日期');
                    return false;
                }
                //检验表单输入是否合法
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {
                        axios.post("/physical/add.do?setmealIds=" + this.setmealIds, this.formData).then((resp) => {
                            //关闭新增窗口
                            this.dialogFormVisible = false;
                            if (resp.data.flag) {
                                this.$message({
                                    message: resp.data.message,
                                    type: 'success'
                                });
                            } else {
                                this.$message.error(resp.data.message);
                            }
                        }).finally(() => {
                            this.findPage();
                        })
                    } else {
                        this.$message.error("表单校验失败");
                        return false;
                    }
                });
            },
            //弹出上传文件窗口
            handleUpdate(row) {
                this.resetForm();
                this.dialogFormVisible4Edit = true;
                //重置
                this.setmealIds = [];
                //为了绑定上传需要的对象,将physical传入到formdata里,但并不显示
                axios.get("/physical/findById.do?id=" + row.id).then((resp) => {
                    if (resp.data.flag) {
                        this.formData = resp.data.data;
                    } else {
                        this.$message.error("查询失败")
                    }
                });
            },
            uploadReportCreate() {
                axios.post("/physical/uploadReport.do" , this.formData).then((resp) => {
                    this.dialogFormVisible4Edit = false;
                    if (resp.data.flag) {
                        this.$message({
                            type: 'success',
                            message: resp.data.message
                        })
                    } else {
                        this.$message.error(resp.data.message)
                    }
                }).finally(()=>{
                    this.findPage();
                    this.imageUrl = null;
                })
            },
            // 重置表单
            resetForm() {
                this.formData = {};//重置数据
            },

            //切换页码
            handleCurrentChange(currentPage) {
                //currentPage为切换后的页码
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            handleDelete(row) {
                this.$confirm("确定要删除吗?", "提示", {type: 'warning'}).then((res) => {
                    axios.get("/physical/deletebyid.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                            this.findPage();
                        } else {
                            this.$message.error(res.data.message);
                        }
                    });
                }).catch(() => {
                    this.$message({
                        message: '已取消',
                        type: 'info'
                    });
                });
            }
        }

    })
</script>
</html>